package com.xsy.android.compose.wandroid.logic.base.viewmodel

import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.xsy.android.compose.wandroid.logic.model.ClassifyModel
import com.xsy.android.compose.wandroid.logic.model.PlayState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

abstract class BaseViewModel(app: Application) : BaseArticleViewModel(app) {
    protected val mutableTreeLiveData = MutableLiveData<PlayState<List<ClassifyModel>>>()
    val treeLiveData: LiveData<PlayState<List<ClassifyModel>>>
        get() = mutableTreeLiveData

    abstract suspend fun getData()

    fun getDataList() {
        viewModelScope.launch(Dispatchers.IO) {
            getData()
        }
    }

    private val _position = MutableLiveData(0)

    val position: LiveData<Int> = _position

    fun onPositionChanged(position: Int) {
        _position.value = position
    }
}